//
//  HomePageMainListViewController.m
//  ShowYork
//
//  Created by hxh on 2021/3/9.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "HomePageMainListViewController.h"
#import "HomePageMomentListViewController.h"
#import "HomePageSegmentedControl.h"
#import "HomePageViewRecommendController.h"
#import "RPNoDataView.h"
@interface HomePageMainListViewController ()
@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)HomePageSegmentedControl *segmentedControl;
@end

@implementation HomePageMainListViewController


- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
        
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUI];
    
    // Do any additional setup after loading the view.
}

- (void)setUI{
    
    self.isHideNavBar = YES;

    __weak typeof(self)weakSelf = self;
    self.segmentedControl = [[HomePageSegmentedControl alloc]initWithCompleteBlock:^(NSInteger index) {
        [weakSelf.scrollView setContentOffset:CGPointMake(kScreenW * index, 0) animated:YES];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"updateHomePageScrollViewContent" object:nil userInfo:@{@"status":index == 1?@(1):@(0)}];
        
    } backBlock:^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    [self.view addSubview:self.segmentedControl];
    
    self.scrollView = [[UIScrollView alloc]init];
    self.scrollView.pagingEnabled = YES;
    self.scrollView.scrollEnabled = NO;
    self.scrollView.contentSize = CGSizeMake(kScreenW * 2, 0);
    [self.view addSubview:self.scrollView];
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.segmentedControl.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    
    HomePageViewRecommendController *recommendVC = [[HomePageViewRecommendController alloc]init];
    HomePageMomentListViewController *momentVC = [[HomePageMomentListViewController alloc]init];
    [self addChildViewController:momentVC];
    [self addChildViewController:recommendVC];
    
    [self.scrollView addSubview:recommendVC.view];
    [self.scrollView addSubview:momentVC.view];
    
    [recommendVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.equalTo(self.scrollView);
        make.leading.mas_equalTo(self.scrollView.mas_leading);
    }];
    [momentVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.equalTo(self.scrollView);
        make.leading.mas_equalTo(recommendVC.view.mas_trailing);
    }];
}



@end
